package com.example.androiddemo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class Lesson5_4Activity extends AppCompatActivity {
    Button bt;
    private String str ="";
    ProgressBar bar;
    private int currentProgress = 0;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lesson5_4);
        /**
         * 点击一个按钮会让ProgressBar（水平类型，最大值为100)
         * 每次增加10个百分点，若点击增 加后超过100，则从零重新计算
         * */
        bt = (Button) findViewById(R.id.btn_add);
        bar = (ProgressBar) findViewById(R.id.progress_btn);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                currentProgress += 10;
                if(currentProgress <= 100){
                    bar.setProgress(currentProgress);
                    str = (String.format("当前进度条为%d/%d",currentProgress,100));
                    // Toast.makeText(this, str, Toast.LENGTH_SHORT).show(); 错误写法 ？？
                    Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();

                }else if(currentProgress > 100){
                    bar.setProgress(currentProgress -100);
                    str = (String.format("当前进度条为%d/%d",currentProgress -100,100));
                    Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();

                }

            }
        });

    }
}
